import { scene } from "./utils/init"
import * as THREE from 'three'
// 初始化基类
class BaseModel {
  constructor (scene) {
    // 颜色 位置 场景 放在基类
    this.color = new THREE.Color(`rgb(${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)})`)
    this.position = [
      Math.floor(Math.random() * (5 - 1 + 1) + 1),
      Math.floor(Math.random() * (5 - 1 + 1) + 1),
      Math.floor(Math.random() * (5 - 1 + 1) + 1),
    ]
    this.scene = scene
    this.model = null // 存储最终的几何体
  }
}

class MySphere extends BaseModel {
  constructor (scene) {
    super(scene)
    // 球体的半径
    this.radius = Math.floor(Math.random () * (3 - 0 + 1) + 0)
    this.init()
  }
  init () {
    const material = new THREE.MeshBasicMaterial({color: this.color})
    const sphere = new THREE.SphereGeometry(this.radius, 32, 16)
    this.model = new THREE.Mesh(sphere, material)
    this.model.position.set(...this.position)
    this.scene.add(this.model)
  }
}

const arr = []
for (let i = 0; i < 5; i++) {
  arr.push(new MySphere(scene))
}
console.log(arr, 'arr');